from django.views import View
from django.http import HttpResponse
from django_redis import get_redis_connection

from verifications.libs.captcha.captcha import captcha
from . import constants


class ImageCodeView(View):
    def get(self, request, uuid):
        name, test, image = captcha.generate_captcha()
        redis_conn = get_redis_connection('verify_code')
        redis_conn.setex('img_%s' % uuid, constants.ICRE, test)
        return HttpResponse(image, content_type='image/jpg')
